class MyPage extends BaseList {
    constructor(orderby, flag, headerId, styleNo, $pagesize, $pagination, listUrl, onLineEditUrl, checkBoxName) {
        super(orderby, flag, $pagesize, $pagination, listUrl, onLineEditUrl, checkBoxName);
        this.headerId = headerId;
        this.styleNo = styleNo;
    }
    GetFilter(pageIndex) {
        let item = super.GetFilter(pageIndex);
        item["HeaderId"] = this.headerId;
        item["StyleNo"] = this.styleNo;
        return JSON.stringify(item);
    }
    FetchAll() {
        this.FetchForPage(1);
    }
    EmptyTableContent() {
        $("#tabData01 tbody").empty();
    }
    SetTableContent(result) {
        $("#tabData01 tbody").empty();
        let content_01 = '';
        this.rows = result.length;  // 设置表格中checkbox的数量为表格的行数
        this.numCheckbox = result.length;  // 设置表格中checkbox的数量为表格的行数
        for (let i = 0; i < result.length; i++) {
            content_01 += '<tr _mash_id="' + result[i].linesId + '">';
            if (parseInt(this.flag) === 0) { // 单选
                content_01 += '<td style="padding-left:9px;"><label class="btn" for="R-' + result[i].linesId + '"><input id="R-' + result[i].linesId + '" name="_select_row" type="radio" onclick="_Instance.OnChoice($(this));" value="' + result[i].linesId + '"/><i></i><span></span></label></td>';
            } else { // 多选
                content_01 += '<td style="padding-left:9px;"><label class="btn" for="R-' + result[i].linesId + '"><input id="R-' + result[i].linesId + '" name="_check_row" type="checkbox" onclick="_Instance.DoCheckRow($(this),$(\'#CheckAll\'));" value="' + result[i].linesId + '"/><i></i><span></span></label></td>';
            }
            content_01 += '<td>' + formatNullData(result[i].destination) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].styleNo) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].productName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].colourName) + '</td>';
            content_01 += '<td style="text-align:center;">' + formatNullData(result[i].sizeName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].moQuantity) + '</td>';
            content_01 += '<td>' + result[i].deliveriedQuantity + '</td>';
            content_01 += '<td>' + formatNullData(result[i].moQuantity - result[i].deliveriedQuantity) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].quantity) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].shippingMarkNo) + '</td>';
            content_01 += '</tr>';
            $('#tabData01 tbody').append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tabData01");
        this.AdjustDataTableHeight();

        $(window).resize();                     // 防止因为出现滚动条而造成画面显示问题
        $('#loading').hide();
    }
    // 选择后执行的动作
    SetChoiceData($self) {
        // 设置选择结果
        let $tr1 = $self.parent().parent().parent();
        //设置选择结果
        return new Array($self.val(), $.trim($tr1.find('td').eq(1).text()));
    }
    // 设置行选择后的状态
    SetRowStatus($self) {
        super.AdjustRowStatus($self, ($row, index) => {
            let key = $self.val();
            let item = {};
            item["doLinesId"] = key;
            this.selectedItemList[key] = item;
        }, ($row, index) => {
            let key = $self.val();
            delete this.selectedItemList[key];
        });
    }
    SortTable(orderBy) {
        this.orderby = orderBy;
        // 得到排序数据
        this.FetchForPage(1);
    }
    AdjustDataTableHeight() {
        let h = $(window).height();
        let _rc = Math.floor((h - 60 - 25) / 25);
        let _dh = _rc * 25;
        let _rowH = this.rows * 25; // 计算行高
        _dh = (_rowH >= _dh) ? _dh : _rowH;
        $("#divD1").css({"max-height": _dh, height: _dh});
    }
}

let _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let flag = jQuery.url.param("flag") === undefined ? 0 : jQuery.url.param("flag");
    let headerId = jQuery.url.param("headerId") === undefined ? 0 : jQuery.url.param("headerId");
    let styleNo = jQuery.url.param("styleNo") === undefined ? "" : jQuery.url.param("styleNo");
    _Instance = new MyPage(null, flag, headerId, styleNo, null, null,
            "/trade/delivery_command_sheet/lines/fetchByHeaderIdAndStyleNo.html",
            "",
            "_check_row");

    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    if (_Instance !== null) {
        _Instance.AdjustDataTableHeight();
    }
}